/*
 * @Description: 
 * @Date: 2025-05-27 14:56:11
 * @LastEditTime: 2025-08-13 14:39:18
 */
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

export default ({ mode }) => {
  // Load app-level env vars to node-level env vars.
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

  return defineConfig({
    devtool: 'source-map',
    plugins: [vue()],
    resolve: {
      alias: [
        {
          find: '@antv/x6',
          replacement: '@antv/x6/lib',
        },
        {
          find: '@antv/x6-vue-shape',
          replacement: '@antv/x6-vue-shape/lib',
        },
        {
          find: 'dagre',
          replacement: 'dagre/dist/dagre.js',
        },
      ],
    },
     base: process.env.VITE_APP_BASE_URI,
    server: {
      host: '0.0.0.0',
      proxy: {
        '/api': {
          target: 'http://10.136.51.197:10009',
          //target: 'http://localhost:10009',   // 后端 API 地址
          changeOrigin: true,                // 改变请求源，避免 CORS 问题
          secure: false,                     // 如果是https接口，需要配置为false
          rewrite: (path) => path.replace(/^\/api/, ''),  // 重写路径，去掉/api前缀
        },
      },
    },
    optimizeDeps: {
      exclude: [
        '@antv/x6',
        '@antv/x6-vue-shape',
        '@antv/x6-plugin-export',
        '@antv/x6/lib',
        '@antv/x6-vue-shape/lib'
        
      ],
    },
    build: {
      commonjsOptions: {
        include: [/node_modules/]
      }
    }
  });
}

